﻿using System;
using System.IO;
using System.Text;
using ReLogic.Utilities;
using Terraria.Chat.Commands;

namespace Terraria.Chat
{
	// Token: 0x0200048D RID: 1165
	public struct ChatCommandId
	{
		// Token: 0x0600274D RID: 10061 RVA: 0x0001B7FB File Offset: 0x000199FB
		private ChatCommandId(string name)
		{
			this._name = name;
		}

		// Token: 0x0600274E RID: 10062 RVA: 0x004946C4 File Offset: 0x004928C4
		public static ChatCommandId FromType<T>() where T : IChatCommand
		{
			ChatCommandAttribute cacheableAttribute = AttributeUtilities.GetCacheableAttribute<T, ChatCommandAttribute>();
			if (cacheableAttribute != null)
			{
				return new ChatCommandId(cacheableAttribute.Name);
			}
			return new ChatCommandId(null);
		}

		// Token: 0x0600274F RID: 10063 RVA: 0x0001B804 File Offset: 0x00019A04
		public void Serialize(BinaryWriter writer)
		{
			writer.Write(this._name ?? "");
		}

		// Token: 0x06002750 RID: 10064 RVA: 0x0001B81B File Offset: 0x00019A1B
		public static ChatCommandId Deserialize(BinaryReader reader)
		{
			return new ChatCommandId(reader.ReadString());
		}

		// Token: 0x06002751 RID: 10065 RVA: 0x0001B828 File Offset: 0x00019A28
		public int GetMaxSerializedSize()
		{
			return 4 + Encoding.UTF8.GetByteCount(this._name ?? "");
		}

		// Token: 0x040043B7 RID: 17335
		private readonly string _name;
	}
}
